<template>
  <div class="content">
    <div class="substance">
      <div
        v-for="(item, index) in courseList"
        :key="index"
        class="table-method"
      >
      <router-link :to="'/details/'+ + item.id">
        <div class="img-box">
          <img :src="getImgUrl(item.courseImage)" class="image" />
        </div>
        <div class="title">
          <h1>{{ item.courseName }}</h1>
          <h2>课程分类：{{ item.courseTypeName }}</h2>
          <h2>课程完成：{{item.learningState == '0'?'课程未完成':'课程已达标'}}</h2>
        </div>
       </router-link>
      </div>
    </div>
    <!-- 详情页 -->
    <router-view/>
  </div>
</template>

<script>
import Cookies from "js-cookie";
import { listCourse } from "@/api/whpx/ksUser";
export default {
  data() {
    return {
      courseList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        ksSpecialty: null,
        userId: null
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getImgUrl(img) {
      return process.env.VUE_APP_BASE_API + img;
    },
    /** 查询课程中心列表 */
    getList() {
      this.loading = true;
      this.queryParams.ksSpecialty = Cookies.get("ksSpecialty");
      this.queryParams.userId = Cookies.get("id");
      listCourse(this.queryParams).then(response => {
        this.courseList = response.rows;
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.content {
  width: 100%;
  padding: 0.2rem;
  box-sizing: border-box;
  background: #fff;
}
.img-box {
  width: 100%;
  position: relative;
  height: 0;
  padding-bottom: 56%;
  cursor: pointer;
  overflow: hidden;
}
.image {
  position: absolute;
  width: 100%;
  height: 100%;
}
.title {
text-align: left;
  h1 {
    color: #1890ff;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.18rem;
    line-height: 32px;
    text-align: left;
  }
  h2 {
    color: rgb(102, 102, 102);
    font-size: 0.12rem;
    line-height: 24px;
  }
}
.substance {
   display: flex;
  flex-wrap: wrap;
  gap: 20px; 
  justify-content: start; 
}
.table-method {
  width: calc((100% - 60px) / 4);
  padding: 10px;
  border: 1px solid #e6ebf5;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.table-method:hover {
  transform: translateY(-5px);
  box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.3),
    -5px -5px 15px rgba(255, 255, 255, 0.8);
}
</style>
